<!doctype html>
<script src="../../../resources/testharness.js"></script>
<script src="../../../resources/testharnessreport.js"></script>
<script src="../../assert_selection.js"></script>
<script>
// hard line break with BiDi
const isMac = navigator.platform.indexOf('Mac') === 0;
const kBehaviors = window.internals ? ['mac', 'win'] : isMac ? ['mac'] : ['win'];
for (const behavior of kBehaviors) {
  if (window.internals) {
    internals.settings.setEditingBehavior(behavior);
    internals.settings.setSelectTrailingWhitespaceEnabled(behavior !== 'mac');
  }

selection_test(
  '<div contenteditable dir="rtl">|\u05D0\u05D1\u05D2 abc \u05D3\u05D4\u05D5<br>edf \u05D6\u05D7\u05D8 abrebg</div>',
  selection => selection.modify('extend', 'backward', 'word'),
  '<div contenteditable dir="rtl">|\u05D0\u05D1\u05D2 abc \u05D3\u05D4\u05D5<br>edf \u05D6\u05D7\u05D8 abrebg</div>',
  `${behavior} 20-0 rtl backward word`);

selection_test(
  '<div contenteditable dir="rtl">\u05D0|\u05D1\u05D2 abc \u05D3\u05D4\u05D5<br>edf \u05D6\u05D7\u05D8 abrebg</div>',
  selection => selection.modify('extend', 'backward', 'word'),
  '<div contenteditable dir="rtl">|\u05D0^\u05D1\u05D2 abc \u05D3\u05D4\u05D5<br>edf \u05D6\u05D7\u05D8 abrebg</div>',
  `${behavior} 20-1 rtl backward word`);

selection_test(
  '<div contenteditable dir="rtl">\u05D0\u05D1|\u05D2 abc \u05D3\u05D4\u05D5<br>edf \u05D6\u05D7\u05D8 abrebg</div>',
  selection => selection.modify('extend', 'backward', 'word'),
  '<div contenteditable dir="rtl">|\u05D0\u05D1^\u05D2 abc \u05D3\u05D4\u05D5<br>edf \u05D6\u05D7\u05D8 abrebg</div>',
  `${behavior} 20-2 rtl backward word`);

selection_test(
  '<div contenteditable dir="rtl">\u05D0\u05D1\u05D2| abc \u05D3\u05D4\u05D5<br>edf \u05D6\u05D7\u05D8 abrebg</div>',
  selection => selection.modify('extend', 'backward', 'word'),
  '<div contenteditable dir="rtl">|\u05D0\u05D1\u05D2^ abc \u05D3\u05D4\u05D5<br>edf \u05D6\u05D7\u05D8 abrebg</div>',
  `${behavior} 20-3 rtl backward word`);

selection_test(
  '<div contenteditable dir="rtl">\u05D0\u05D1\u05D2 |abc \u05D3\u05D4\u05D5<br>edf \u05D6\u05D7\u05D8 abrebg</div>',
  selection => selection.modify('extend', 'backward', 'word'),
  '<div contenteditable dir="rtl">|\u05D0\u05D1\u05D2 ^abc \u05D3\u05D4\u05D5<br>edf \u05D6\u05D7\u05D8 abrebg</div>',
  `${behavior} 20-4 rtl backward word`);

selection_test(
  '<div contenteditable dir="rtl">\u05D0\u05D1\u05D2 a|bc \u05D3\u05D4\u05D5<br>edf \u05D6\u05D7\u05D8 abrebg</div>',
  selection => selection.modify('extend', 'backward', 'word'),
  '<div contenteditable dir="rtl">\u05D0\u05D1\u05D2 |a^bc \u05D3\u05D4\u05D5<br>edf \u05D6\u05D7\u05D8 abrebg</div>',
  `${behavior} 20-5 rtl backward word`);

selection_test(
  '<div contenteditable dir="rtl">\u05D0\u05D1\u05D2 ab|c \u05D3\u05D4\u05D5<br>edf \u05D6\u05D7\u05D8 abrebg</div>',
  selection => selection.modify('extend', 'backward', 'word'),
  '<div contenteditable dir="rtl">\u05D0\u05D1\u05D2 |ab^c \u05D3\u05D4\u05D5<br>edf \u05D6\u05D7\u05D8 abrebg</div>',
  `${behavior} 20-6 rtl backward word`);

selection_test(
  '<div contenteditable dir="rtl">\u05D0\u05D1\u05D2 abc| \u05D3\u05D4\u05D5<br>edf \u05D6\u05D7\u05D8 abrebg</div>',
  selection => selection.modify('extend', 'backward', 'word'),
  '<div contenteditable dir="rtl">\u05D0\u05D1\u05D2 |abc^ \u05D3\u05D4\u05D5<br>edf \u05D6\u05D7\u05D8 abrebg</div>',
  `${behavior} 20-7 rtl backward word`);

selection_test(
  '<div contenteditable dir="rtl">\u05D0\u05D1\u05D2 abc |\u05D3\u05D4\u05D5<br>edf \u05D6\u05D7\u05D8 abrebg</div>',
  selection => selection.modify('extend', 'backward', 'word'),
  '<div contenteditable dir="rtl">\u05D0\u05D1\u05D2 |abc ^\u05D3\u05D4\u05D5<br>edf \u05D6\u05D7\u05D8 abrebg</div>',
  `${behavior} 20-8 rtl backward word`);

selection_test(
  '<div contenteditable dir="rtl">\u05D0\u05D1\u05D2 abc \u05D3|\u05D4\u05D5<br>edf \u05D6\u05D7\u05D8 abrebg</div>',
  selection => selection.modify('extend', 'backward', 'word'),
  '<div contenteditable dir="rtl">\u05D0\u05D1\u05D2 abc |\u05D3^\u05D4\u05D5<br>edf \u05D6\u05D7\u05D8 abrebg</div>',
  `${behavior} 20-9 rtl backward word`);

selection_test(
  '<div contenteditable dir="rtl">\u05D0\u05D1\u05D2 abc \u05D3\u05D4|\u05D5<br>edf \u05D6\u05D7\u05D8 abrebg</div>',
  selection => selection.modify('extend', 'backward', 'word'),
  '<div contenteditable dir="rtl">\u05D0\u05D1\u05D2 abc |\u05D3\u05D4^\u05D5<br>edf \u05D6\u05D7\u05D8 abrebg</div>',
  `${behavior} 20-10 rtl backward word`);

selection_test(
  '<div contenteditable dir="rtl">\u05D0\u05D1\u05D2 abc \u05D3\u05D4\u05D5<br>|edf \u05D6\u05D7\u05D8 abrebg</div>',
  selection => selection.modify('extend', 'backward', 'word'),
  '<div contenteditable dir="rtl">\u05D0\u05D1\u05D2 abc \u05D3\u05D4\u05D5|<br>^edf \u05D6\u05D7\u05D8 abrebg</div>',
  `${behavior} 20-11 rtl backward word`);

selection_test(
  '<div contenteditable dir="rtl">\u05D0\u05D1\u05D2 abc \u05D3\u05D4\u05D5<br>e|df \u05D6\u05D7\u05D8 abrebg</div>',
  selection => selection.modify('extend', 'backward', 'word'),
  '<div contenteditable dir="rtl">\u05D0\u05D1\u05D2 abc \u05D3\u05D4\u05D5<br>|e^df \u05D6\u05D7\u05D8 abrebg</div>',
  `${behavior} 20-12 rtl backward word`);

selection_test(
  '<div contenteditable dir="rtl">\u05D0\u05D1\u05D2 abc \u05D3\u05D4\u05D5<br>ed|f \u05D6\u05D7\u05D8 abrebg</div>',
  selection => selection.modify('extend', 'backward', 'word'),
  '<div contenteditable dir="rtl">\u05D0\u05D1\u05D2 abc \u05D3\u05D4\u05D5<br>|ed^f \u05D6\u05D7\u05D8 abrebg</div>',
  `${behavior} 20-13 rtl backward word`);

selection_test(
  '<div contenteditable dir="rtl">\u05D0\u05D1\u05D2 abc \u05D3\u05D4\u05D5<br>edf| \u05D6\u05D7\u05D8 abrebg</div>',
  selection => selection.modify('extend', 'backward', 'word'),
  '<div contenteditable dir="rtl">\u05D0\u05D1\u05D2 abc \u05D3\u05D4\u05D5<br>|edf^ \u05D6\u05D7\u05D8 abrebg</div>',
  `${behavior} 20-14 rtl backward word`);

selection_test(
  '<div contenteditable dir="rtl">\u05D0\u05D1\u05D2 abc \u05D3\u05D4\u05D5<br>edf |\u05D6\u05D7\u05D8 abrebg</div>',
  selection => selection.modify('extend', 'backward', 'word'),
  '<div contenteditable dir="rtl">\u05D0\u05D1\u05D2 abc \u05D3\u05D4\u05D5<br>|edf ^\u05D6\u05D7\u05D8 abrebg</div>',
  `${behavior} 20-15 rtl backward word`);

selection_test(
  '<div contenteditable dir="rtl">\u05D0\u05D1\u05D2 abc \u05D3\u05D4\u05D5<br>edf \u05D6|\u05D7\u05D8 abrebg</div>',
  selection => selection.modify('extend', 'backward', 'word'),
  '<div contenteditable dir="rtl">\u05D0\u05D1\u05D2 abc \u05D3\u05D4\u05D5<br>edf |\u05D6^\u05D7\u05D8 abrebg</div>',
  `${behavior} 20-16 rtl backward word`);

selection_test(
  '<div contenteditable dir="rtl">\u05D0\u05D1\u05D2 abc \u05D3\u05D4\u05D5<br>edf \u05D6\u05D7|\u05D8 abrebg</div>',
  selection => selection.modify('extend', 'backward', 'word'),
  '<div contenteditable dir="rtl">\u05D0\u05D1\u05D2 abc \u05D3\u05D4\u05D5<br>edf |\u05D6\u05D7^\u05D8 abrebg</div>',
  `${behavior} 20-17 rtl backward word`);

selection_test(
  '<div contenteditable dir="rtl">\u05D0\u05D1\u05D2 abc \u05D3\u05D4\u05D5<br>edf \u05D6\u05D7\u05D8| abrebg</div>',
  selection => selection.modify('extend', 'backward', 'word'),
  '<div contenteditable dir="rtl">\u05D0\u05D1\u05D2 abc \u05D3\u05D4\u05D5<br>edf |\u05D6\u05D7\u05D8^ abrebg</div>',
  `${behavior} 20-18 rtl backward word`);

selection_test(
  '<div contenteditable dir="rtl">\u05D0\u05D1\u05D2 abc \u05D3\u05D4\u05D5<br>edf \u05D6\u05D7\u05D8 |abrebg</div>',
  selection => selection.modify('extend', 'backward', 'word'),
  '<div contenteditable dir="rtl">\u05D0\u05D1\u05D2 abc \u05D3\u05D4\u05D5<br>edf |\u05D6\u05D7\u05D8 ^abrebg</div>',
  `${behavior} 20-19 rtl backward word`);

selection_test(
  '<div contenteditable dir="rtl">\u05D0\u05D1\u05D2 abc \u05D3\u05D4\u05D5<br>edf \u05D6\u05D7\u05D8 a|brebg</div>',
  selection => selection.modify('extend', 'backward', 'word'),
  '<div contenteditable dir="rtl">\u05D0\u05D1\u05D2 abc \u05D3\u05D4\u05D5<br>edf \u05D6\u05D7\u05D8 |a^brebg</div>',
  `${behavior} 20-20 rtl backward word`);

selection_test(
  '<div contenteditable dir="rtl">\u05D0\u05D1\u05D2 abc \u05D3\u05D4\u05D5<br>edf \u05D6\u05D7\u05D8 ab|rebg</div>',
  selection => selection.modify('extend', 'backward', 'word'),
  '<div contenteditable dir="rtl">\u05D0\u05D1\u05D2 abc \u05D3\u05D4\u05D5<br>edf \u05D6\u05D7\u05D8 |ab^rebg</div>',
  `${behavior} 20-21 rtl backward word`);

selection_test(
  '<div contenteditable dir="rtl">\u05D0\u05D1\u05D2 abc \u05D3\u05D4\u05D5<br>edf \u05D6\u05D7\u05D8 abr|ebg</div>',
  selection => selection.modify('extend', 'backward', 'word'),
  '<div contenteditable dir="rtl">\u05D0\u05D1\u05D2 abc \u05D3\u05D4\u05D5<br>edf \u05D6\u05D7\u05D8 |abr^ebg</div>',
  `${behavior} 20-22 rtl backward word`);

selection_test(
  '<div contenteditable dir="rtl">\u05D0\u05D1\u05D2 abc \u05D3\u05D4\u05D5<br>edf \u05D6\u05D7\u05D8 abre|bg</div>',
  selection => selection.modify('extend', 'backward', 'word'),
  '<div contenteditable dir="rtl">\u05D0\u05D1\u05D2 abc \u05D3\u05D4\u05D5<br>edf \u05D6\u05D7\u05D8 |abre^bg</div>',
  `${behavior} 20-23 rtl backward word`);

selection_test(
  '<div contenteditable dir="rtl">\u05D0\u05D1\u05D2 abc \u05D3\u05D4\u05D5<br>edf \u05D6\u05D7\u05D8 abreb|g</div>',
  selection => selection.modify('extend', 'backward', 'word'),
  '<div contenteditable dir="rtl">\u05D0\u05D1\u05D2 abc \u05D3\u05D4\u05D5<br>edf \u05D6\u05D7\u05D8 |abreb^g</div>',
  `${behavior} 20-24 rtl backward word`);

selection_test(
  '<div contenteditable dir="rtl">\u05D0\u05D1\u05D2 abc \u05D3\u05D4\u05D5<br>edf \u05D6\u05D7\u05D8 abrebg|</div>',
  selection => selection.modify('extend', 'backward', 'word'),
  '<div contenteditable dir="rtl">\u05D0\u05D1\u05D2 abc \u05D3\u05D4\u05D5<br>edf \u05D6\u05D7\u05D8 |abrebg^</div>',
  `${behavior} 20-25 rtl backward word`);
}
</script>
